<template>
    <div>
      <div style="display:flex;justify-content: space-between">
        <el-button type="primary" size="mini" icon="el-icon-plus" @click="showAddSalaryView">添加工资账套</el-button>
        <el-button type="success" size="mini" icon="el-icon-refresh" @click="initSalaries"></el-button>
      </div>
      <div style="margin-top: 10px">
        <el-table :data="salaries"
                  border
                  stripe
        >
          <el-table-column type="selection" width="40px">
          </el-table-column>
          <el-table-column
              prop="name"
              width="120px"
              label="账套名称">
          </el-table-column>
          <el-table-column
              prop="basicSalary"
              width="80px"
              label="基本工资">
          </el-table-column>
          <el-table-column
              prop="trafficSalary"
              width="80px"
              label="交通补助">
          </el-table-column>
          <el-table-column
              prop="lunchSalary"
              width="80px"
              label="午餐补助">
          </el-table-column>
          <el-table-column
              prop="bonus"
              width="50px"
              label="奖金">
          </el-table-column>
          <el-table-column
              prop="createDate"
              width="100px"
              label="启用时间">
          </el-table-column>
          <el-table-column
              align="center"
              label="养老金">
            <el-table-column
                prop="pensionPer"
                label="比率" width="50px">
            </el-table-column>
            <el-table-column
                prop="pensionBase"
                label="基数" width="60px">
            </el-table-column>
          </el-table-column>
          <el-table-column
              align="center"
              label="医疗保险">
            <el-table-column
                prop="medicalPer"
                label="比率" width="50px">
            </el-table-column>
            <el-table-column
                prop="medicalBase"
                label="基数" width="60px">
            </el-table-column>
          </el-table-column>
          <el-table-column
              align="center"
              label="公积金">
            <el-table-column
                prop="accumulationFundPer"
                label="比率" width="50px">
            </el-table-column>
            <el-table-column
                prop="accumulationFundBase"
                label="基数" width="60px">
            </el-table-column>
          </el-table-column>
          <el-table-column label="操作" style="display: flex">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" style="width: 50px" @click="showEditSalaryView(scope.row)">编辑</el-button>
              <el-button type="danger" size="mini" style="width: 50px" @click="deleteSalary(scope.row)">删除</el-button>
            </template>

          </el-table-column>
        </el-table>
      </div>
      <el-dialog
          :title="dialogTitle"
          :visible.sync="dialogVisible"
          width="50%"
          >
        <div style="display: flex;justify-content: space-around;align-items: center">
          <el-steps direction="vertical" :active="activeItemIndex">
            <el-step :title="itemName" v-for="(itemName,index) in salaryItemName" :key="index"></el-step>
          </el-steps>
          <el-input :placeholder="'请输入'+salaryItemName[index]+'...'"
                    v-for="(value,title,index) in salary" :key="index"
                    v-show="activeItemIndex==index"
                    v-model="salary[title]"
                    style="width: 200px" size="mini"></el-input>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="preStep" size="mini">{{activeItemIndex==10?"取 消":"上一步"}}</el-button>
          <el-button type="primary" @click="nextStep" size="mini">{{activeItemIndex==10?"完 成":"下一步"}}</el-button>
        </span>
      </el-dialog>
    </div>
</template>

<script>

export default {
  name: "SalSob",
  data(){
    return {
      dialogTitle:"添加工资账套",
      salaries:[],
      activeItemIndex:0,
      dialogVisible:false,
      salaryItemName:[
          "账套名称","基本工资","交通补助","午餐补助","奖金","养老金比率","养老金基数",
        "医疗保险比率","医疗保险基数","公积金比率","公积金基数"

      ],
      salary:{
        name:"",
        basicSalary:0,
        trafficSalary:0,
        lunchSalary:0,
        bonus:0,
        pensionPer:0,
        pensionBase:0,
        medicalPer:0,
        medicalBase:0,
        accumulationFundPer:0,
        accumulationFundBase:0
      },
    }
  },
  mounted() {
    this.initSalaries()
  },
  methods:{
    showEditSalaryView(data){debugger
      this.activeItemIndex = 0;
      this.dialogTitle = "编辑工资账套";
      this.dialogVisible = true;
      this.salary.id = data.id;
      this.salary.name = data.name,
      this.salary.basicSalary = data.basicSalary,
      this.salary.trafficSalary = data.trafficSalary,
      this.salary.lunchSalary = data.lunchSalary,
      this.salary.bonus = data.bonus,
      this.salary.pensionPer = data.pensionPer,
      this.salary.pensionBase = data.pensionBase,
      this.salary.medicalPer= data.medicalPer,
      this.salary.medicalBase = data.medicalBase,
      this.salary.accumulationFundPer = data.accumulationFundPer,
      this.salary.accumulationFundBase = data.accumulationFundBase
    },
    //删除工资账套
    deleteSalary(data){
      this.$confirm('此操作将永久删除['+data.name+']工资账套, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$deleteRequest("/salary/sob/"+data.id).then(resp=>{
          if(resp){
            this.initSalaries();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    preStep(){
      if(this.activeItemIndex===0){
        return;
      }else  if(this.activeItemIndex===10){
        this.dialogVisible = false;
        return;
      }
      this.activeItemIndex--;
    },
    nextStep(){
      if(this.activeItemIndex===10){
        if(this.salary.id){
          this.$putRequest("/salary/sob/",this.salary).then(resp=>{
            if(resp){
              this.dialogVisible = false;
              this.initSalaries();
            }
          })
        }else{
          this.$postRequest("/salary/sob/",this.salary).then(resp=>{
            if(resp){
              this.dialogVisible = false;
              this.initSalaries();
            }
          })
        }
        return;
      }
      this.activeItemIndex++;
    },
    //编辑页面展示
    showAddSalaryView(){
      this.dialogTitle = "添加工资账套";
      this.salary = {
            name:"",
            basicSalary:0,
            trafficSalary:0,
            lunchSalary:0,
            bouns:0,
            pensionPer:0,
            pensionBase:0,
            medicalPer:0,
            medicalBase:0,
            accumulationFundPer:0,
            accumulationFundBase:0
      },
      this.activeItemIndex = 0;
      this.dialogVisible = true;
    },
    //初始化工资账套
    initSalaries(){
        this.$getRequest("/salary/sob/").then(resp=>{
          if(resp){
            this.salaries = resp;
          }
        })
    }
  }
}
</script>

<style scoped>

</style>